package com.holyland.util;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class MailUtil {
	
	public static void sendEmail(String recipientEmail, String recipientName, String subject, String message) throws UnsupportedEncodingException, MessagingException {
		Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        
		Message msg = new MimeMessage(session);
		msg.setFrom(new InternetAddress("hbc.indonesia@gmail.com", "PT. HBC Admin"));
		msg.addRecipient(Message.RecipientType.TO,
                new InternetAddress(recipientEmail, recipientName));
		msg.addRecipient(Message.RecipientType.BCC,
                new InternetAddress("hbc.indonesia@gmail.com", "PT. HBC Admin"));
		msg.setSubject(subject);
					
		MimeBodyPart body = new MimeBodyPart();
		body.setContent(message, "text/html");						
		
		Multipart mp = new MimeMultipart();
        mp.addBodyPart(body);
        
        msg.setContent(mp);						
		
		Transport.send(msg);		
	}
}
